package applications.camoverlay;

import java.io.IOException;
import android.hardware.Camera;
import android.view.SurfaceHolder;

public class SurfaceCallback implements SurfaceHolder.Callback{
	
	private boolean active;
	public static Camera camera;
	
	public void surfaceCreated(SurfaceHolder holder) {
		camera=Camera.open();
	}

	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
		if (active) {
			camera.stopPreview();
		}

		try {
			camera.setPreviewDisplay(holder);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		Camera.Parameters p = camera.getParameters();
		p.setPreviewSize(width, height);
		camera.setParameters(p);
		
		camera.startPreview();
		active = true;
		
	}

	public void surfaceDestroyed(SurfaceHolder holder) {
		camera.stopPreview();
		active = false;
		camera.release();
	}

}